package com.mgvlife.ddlw.action;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.mgvlife.ddlw.formbean.SuperAdminForm;
import com.mgvlife.ddlw.service.SuperAdminService;
import com.mgvlife.ddlw.util.HttpSessionUtil;
import com.mgvlife.ddlw.vo.Result;
import com.mgvlife.ddlw.vo.VoSuperAdmin;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.xinhuo.util.JsonUtil;
import com.xinhuo.vo.JsonEasyUI;

@Controller("superAdminAction")
@Scope("prototype")
public class SuperAdminAction extends ActionSupport implements
		ModelDriven<SuperAdminForm> {

	private static final long serialVersionUID = -3280458590794697134L;
	private SuperAdminForm dataForm = new SuperAdminForm();
	@Resource
	private SuperAdminService superAdminService = null;

	public void login() {
		Result result = null;
		try {
			result = superAdminService.superAdminLogin(dataForm);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			JsonUtil.output(result);
		}
	}

	public String logOut() {
		HttpSessionUtil.removeSuperAdmin();
		return "logout";
	}

	public void update() {
		Result result = null;
		try {
			result = superAdminService.superAdminUpdate(dataForm);
		} catch (Exception e) {
			e.printStackTrace();
			result = Result.unknownError();
		} finally {
			JsonUtil.output(result);
		}
	}

	public void list() {
		JsonEasyUI<VoSuperAdmin> result = null;
		try {
			result = superAdminService.getData(dataForm);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			JsonUtil.output(result);
		}
	}

	@Override
	public SuperAdminForm getModel() {
		return dataForm;
	}

}
